﻿@using DCMS.Web.Extensions;
@using DCMS.Web.Framework;
@using DCMS.Web.Framework.UI;
@using DCMS.Core.Domain.Common;
@using DCMS.ViewModel.Models.Finances;
@using DCMS.Core;
@using DCMS.Core.Infrastructure;

@model RecordingVoucherListModel

@{
    var _webHelper = EngineContext.Current.Resolve<IWebHelper>();
}
<section id="content_wrapper">

    <!-- Start: Topbar-Dropdown -->
    <div id="topbar-dropmenu">
        @await Html.PartialAsync("_ToolBox")
    </div>
    <!-- End: Topbar-Dropdown -->
    <!-- Start: Topbar -->
    <header id="topbar">
        <div class="topbar-left">
            <ol class="breadcrumb">
                <li class="crumb-active">
                    <a href="#">财务</a>
                </li>
                <li class="crumb-icon">
                    <a href="@Url.RouteUrl("HomePage")">
                        <span class="glyphicon glyphicon-home"></span>
                    </a>
                </li>
                <li class="crumb-link">
                    <a href="#">财务凭证</a>
                </li>
                <li class="crumb-trail">凭证列表</li>
            </ol>
        </div>
        <div class="topbar-right">
            <div class="ml15 ib va-m" id="toggle_sidemenu_r">
                <a href="#" class="pl5">
                    <i class="fa fa-sign-in fs22 text-primary"></i>
                    <span class="badge badge-hero badge-danger">3</span>
                </a>
            </div>
        </div>
    </header>
    <!-- End: Topbar -->
    <!-- Begin: Content -->
    <section id="content" class="formSection">

        <div class="special-alerts">
            <div class="alert alert-danger light alert-dismissable" id="alert-demo-2" style="display: none;">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                <i class="fa fa-info pr10"></i>
                <strong>您没有被授权此操作!</strong>
            </div>
        </div>

        <div class="row">
            <div class="col-md-12">

                <form asp-action="List" asp-controller="RecordingVoucher" method="get" id="formSearch" novalidate="novalidate">
                    <div class="panel panel-default" id="panel0">
                        <div class="panel-heading">
                            <span class="glyphicon glyphicon-search"></span> 高级搜索
                            <a class="btn btn-default btn-sm pull-right m5 mrn p5 pbn" id="AdvancedSearch"><i class="fa fa-angle-double-right"></i></a>
                        </div>
                        <div class="panel-body p10">

                            <div class="row">
                                <div class="col-sm-2">
                                    <input asp-for="RecordName" class="form-control" placeholder="凭证..." />
                                </div>
                                <div class="col-sm-2">
                                    <dcms-select asp-for="GenerateModeId" asp-items="@Html.GetEnumSelectList<GenerateMode>().ToSelectListDescription<GenerateMode>()" asp-default="生成方式" />
                                </div>
                                <div class="col-sm-2">
                                    <input asp-for="BillNumber" class="form-control" placeholder="单据编号..." />
                                </div>
                                <div class="col-sm-2">
                                    <input asp-for="Summary" class="form-control" placeholder="摘要..." />
                                </div>
                                <div class="col-sm-2">
                                    <div class="input-group">
                                        <input asp-for="AccountingOptionId" type="hidden" />
                                        <input  asp-for="AccountingOptionName" class="form-control" placeholder="科目..." />
                                        <span class="input-group-btn">
                                            <button id="btn_search_accounting" type="button" class="btn btn-default" style="border:1px solid #dddddd;"><span class="glyphicon glyphicon-search"></span></button>
                                        </span>
                                    </div>
                                </div>
                                <div class="col-sm-2">
                                    <dcms-select-bool asp-for="AuditedStatus" asp-items="@(new string[] {  "已审核", "未审核"})" asp-default="审核状态" />
                                </div>
                            </div>

                            <div class="row mt10">
                                <div class="col-sm-2">
                                    <dcms-editor asp-for="StartTime" placeholder="开始..." />
                                </div>
                                <div class="col-sm-2">
                                    <dcms-editor asp-for="EndTime" placeholder="结束..." />
                                </div>

                                <div class="col-sm-2">
                                    <dcms-select asp-for="BillTypeId" asp-items="@Model.BillTypes" class="form-control" asp-default="单据类型" />
                                </div>
                                <div class="col-sm-6">
                                    <button id="btn_query" type="submit" class="btn btn-primary btn-block">
                                        <span class="glyphicon glyphicon-search mr5" aria-hidden="true"></span>查询
                                    </button>
                                </div>
                            </div>

                        </div>
                    </div>
                </form>

                <div class="panel">
                    <div class="panel-heading">
                        <div class="panel-title">
                            <span class="glyphicon glyphicon-tasks"></span> 凭证列表
                        </div>
                    </div>
                    <div class="panel-body p10">

                        <!--Begin _Toolbar-->
                        @await Html.PartialAsync("_Toolbar", Model)
                        <!--End _Toolbar-->

                        <div class="bootstrap-table">

                            <div class="fixed-table-container">
                                <div class="fixed-table-body">

                                    <table class="table table-striped table-bordered table-hover">
                                        <thead>
                                            <tr>
                                                <th class="bs-checkbox " style="text-align: center; vertical-align: middle; width: 36px; ">
                                                    <div class="th-inner "><input name="btSelectAll" type="checkbox"></div>
                                                </th>
                                                <th class="text-center"><div class="th-inner">日期</div></th>
                                                <th class="text-left"><div class="th-inner">凭证字号</div></th>
                                                <th class="text-left"><div class="th-inner">单据编号</div></th>
                                                <th class="text-center">详细</th>
                                                <th class="text-left"><div class="th-inner">摘要</div></th>
                                                <th class="text-left"><div class="th-inner">科目</div></th>
                                                <th class="text-right"><div class="th-inner">借方金额</div></th>
                                                <th class="text-right"><div class="th-inner">贷方金额</div></th>
                                                <th class="text-center"><div class="th-inner">状态</div></th>
                                                <th class="text-left"><div class="th-inner">生成方式</div></th>
                                                <th class="text-left"><div class="th-inner">制单人</div></th>
                                                <th class="text-left"><div class="th-inner">审核人</div></th>
                                                <th class="text-center"><div class="th-inner">操作</div></th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            @{
                                                if (Model.Items == null || Model.Items.Count == 0)
                                                {
                                                    <tr class="no-records-found"><td colspan="14">没有找到匹配的记录</td></tr>
                                                }
                                                else
                                                {
                                                    foreach (var item in Model.Items)
                                                    {

                                                        int i = 0;
                                                        bool child = item.Vouchers.Count > 1;
                                                        int rowspan = 1;
                                                        //int rowspan = item.Vouchers.Count;
                                                        foreach (var voucher in item.Vouchers)
                                                        {
                                                            if (i == 0)
                                                            {
                                                                <tr>
                                                                    <td class="bs-checkbox" @(child ? "rowspan=" + rowspan + "" : "")>
                                                                        <input name="btSelectItem" class="btSelectItem" type="checkbox" value="@item.Id">
                                                                    </td>
                                                                    <td class="text-center" @(child ? "rowspan=" + rowspan + "" : "")>@(item.RecordTime.ToString("yyyy/MM/dd"))</td>
                                                                    <td class="text-left" @(child ? "rowspan=" + rowspan + "" : "")>
                                                                        <a href="#">@(item.RecordName + "-" + item.RecordNumber)</a>
                                                                    </td>
                                                                    <td class="text-left" @(child ? "rowspan=" + rowspan + "" : "")>
                                                                        <a href="@item.BillLink" target="_blank">@item.BillNumber</a>
                                                                    </td>

                                                                    <!--折叠-->
                                                                    <td class="text-center" @(child ? "rowspan=" + rowspan + "" : "")>
                                                                        <a href="javascript:;" class="showChildRow" data-id="@item.Id" data-open="false"><i class="fa fa-plus"></i></a>
                                                                    </td>

                                                                    <td class="text-left">@voucher.Summary</td>
                                                                    <td class="text-left">@(voucher.AccountingOptionId + " " + voucher.AccountingOptionName)</td>
                                                                    <td class="text-right">￥ @voucher.DebitAmount.Value.ToString("0.00")</td>
                                                                    <td class="text-right">￥ @voucher.CreditAmount.Value.ToString("0.00")</td>

                                                                    <td class="text-center" @(child ? "rowspan=" + rowspan + "" : "")>
                                                                        @Html.Raw(item.AuditedStatus ? "<span class=\"label label-success\">已审核</span>" : "<span class=\"label label-danger\">未审核</span>")
                                                                    </td>
                                                                    <td class="text-left" @(child ? "rowspan=" + rowspan + "" : "")>
                                                                        @item.GenerateModeName
                                                                    </td>
                                                                    <td class="text-left" @(child ? "rowspan=" + rowspan + "" : "")>
                                                                        @item.MakeUserName
                                                                    </td>
                                                                    <td class="text-left" @(child ? "rowspan=" + rowspan + "" : "")>
                                                                        @item.AuditedUserName
                                                                    </td>
                                                                    <td class="text-center" @(child ? "rowspan=" + rowspan + "" : "")>

                                                                        @if (item.AuditedStatus || item.BillNumber.StartsWith("settle") || item.BillNumber.StartsWith("CostOf"))
                                                                        {
                                                                            <a class="btn btn-sm btn-success" data-id="@item.Id" href="@Url.Action("view", new { id = item.Id ,returnUrl=_webHelper.GetThisPageUrl(true) })" title="查看">
                                                                                <i class="glyphicon glyphicon-eye-open mr5"></i> 查看
                                                                            </a>
                                                                        }
                                                                        else

                                                                        {

                                                                            <a class="btn btn-sm btn-primary" data-id="@item.Id" href="@Url.Action("edit", new { id = item.Id })" title="编辑">
                                                                                <i class="glyphicon glyphicon-pencil mr5"></i> 编辑
                                                                            </a>
                                                                        }

                                                                    </td>

                                                                </tr>
                                                            }
                                                            else
                                                            {
                                                                <tr class="showChildRow_@item.Id" style="display:none">
                                                                    <td colspan="5"></td>
                                                                    <td class="text-left">@voucher.Summary</td>
                                                                    <td class="text-left">@(voucher.AccountingOptionId + " " + voucher.AccountingOptionName)</td>
                                                                    <td class="text-right">￥ @((voucher.DebitAmount ?? 0).ToString("#,##0.00"))</td>
                                                                    <td class="text-right">￥ @((voucher.CreditAmount ?? 0).ToString("#,##0.00"))</td>
                                                                    <td colspan="5"></td>

                                                                </tr>
                                                            }
                                                            i++;
                                                        }
                                                    }
                                                }

                                            }
                                        </tbody>
                                    </table>
                                </div>
                            </div>

                            @{
                                var pager = Html.Pager(Model.PagingFilteringContext).QueryParam("pagenumber");
                            }

                            @if (!pager.IsEmpty())
                            {
                                <div class="fixed-table-pagination" style="display: block;">
                                    @Html.Raw(pager.ToString())
                                </div>
                            }
                        </div>
                        <div class="clearfix"></div>
                    </div>
                </div>
            </div>
        </div>


    </section>

    <!-- End: Content -->
</section>


@await Html.PartialAsync("_Windows", Model)


@{
//Html.AddCssFileParts(ResourceLocation.Head, "~/assets/skin/default_skin/css/theme.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/Scripts/Toastr/toastr.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/Scripts/Tables/bootstrap-table.css");

//Html.AddCssFileParts(ResourceLocation.Head, "~/vendor/plugins/datepicker/css/bootstrap-datetimepicker.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/vendor/plugins/daterange/daterangepicker.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/vendor/plugins/colorpicker/css/bootstrap-colorpicker.min.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/vendor/plugins/tagmanager/tagmanager.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/vendor/plugins/fancytree/skin-win8/ui.fancytree.min.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/Content/zTree.theme.metro.min.css");

//Html.AddCssFileParts(ResourceLocation.Head, "~/Content/Site.css");

//Html.AddCssFileParts(ResourceLocation.Head, "~/vendor/plugins/spin/spin.css");
//Html.AddCssFileParts(ResourceLocation.Head, "~/vendor/plugins/ladda/ladda.min.css");

}




@section CurPageScripts
{
    @{
//Html.AddScriptParts(ResourceLocation.Footer, "~/assets/js/utility/jquery.sparkline.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/jquery.validate.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/jquery.validate.unobtrusive.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/Tables/jquery.treegrid.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/Tables/bootstrap-table.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/Tables/locale/bootstrap-table-zh-CN.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/Tables/bootstrap-table-treegrid.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/globalize.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/moment.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/moment-with-locales.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/vendor/plugins/daterange/daterangepicker.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/vendor/plugins/datepicker/js/bootstrap-datetimepicker.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/vendor/plugins/colorpicker/js/bootstrap-colorpicker.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/vendor/plugins/jquerymask/jquery.maskedinput.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/vendor/plugins/tagmanager/tagmanager.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/vendor/plugins/fancytree/jquery.fancytree-all.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/jquery.ztree.all-3.5.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/assets/js/bootstrap/holder.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/Toastr/Toastr.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/Scripts/Custom/Common.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/vendor/plugins/spin/spin.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/vendor/plugins/ladda/ladda.min.js");
//Html.AddScriptParts(ResourceLocation.Footer, "~/assets/js/bootstrap/holder.min.js");
    }
    <script type="text/javascript">

        jQuery(document).ready(function () {

            "use strict";

            // Init Theme Core
            Core.init();

            // Init Demo JS
            Demo.init();

            //权限提示
            if ($(this).getUrlQueryString("Authorize") == "noAuthorize") {
                $('#alert-demo-2').fadeToggle();
                setTimeout(function () {
                    $('#alert-demo-2').fadeToggle();
                }, 3000);
            }

            //全选
            $("input[name='btSelectAll']").click(function () {
                var selectStatus = $(this).is(':checked')
                if (selectStatus) {
                    $("input[name='btSelectItem']").each(function (i, n) {
                        n.checked = true;
                    });
                } else {
                    $("input[name='btSelectItem']").each(function (i, n) {
                        n.checked = false;
                    });
                }
            });

            //高级搜索
            $("#panel0 #AdvancedSearch").click(function () {
                var ico = $(this).find(".fa");
                if (ico.hasClass('fa-angle-double-right'))
                    ico.removeClass("fa-angle-double-right").addClass("fa-angle-double-down");
                else
                    ico.removeClass("fa-angle-double-down").addClass("fa-angle-double-right");
                $("#panel0").find(".panel-body").toggleClass("hidden fadeIn");
            });

            //客户搜索
            $(document).on('click', "#btn_search_customer", function () {
                var actionUrl = "/Terminal/AsyncSearchSelectPopup";
                $(this).showModalV2($("#TerminalSelectModalWindow"), actionUrl, { ids: "" }, "选择终端", $("#TerminalSelectForm"), function (rows) { });
            });

            //会计科目选择
            $(document).on('click', "#btn_search_accounting", function () {
                var actionUrl = "/Accounting/AsyncSearchSelectPopup?type=1&ifcheck=1&billTypeId=0";
                //$(this).accountingSearchSelectPopup($("#AccountingModalWindow"), actionUrl, null, "选择科目", $("#AccountingForm"), 0, function (options) {
                //    $("#AccountingOptionId").val(options[0].Id);
                //    $("#AccountingOptionName").val(options[0].name);
                //});
                $(this).accountingSingleSelectPopup($("#AccountingModalWindow"), actionUrl, 1, "选择科目", $("#AccountingForm"), null, function (options) {
                    $("#AccountingOptionId").val(options[0].Id);
                    $("#AccountingOptionName").val(options[0].name);
                });
                //$(this).accountingSearchSelectPopup($("#AccountingModalWindow"), actionUrl, null, "选择科目", $("#AccountingForm"), null, null);
            });

            window.operateEventsPopTerminal = {
                'click .rowSelect': function (e, value, row, index) {
                    try {
                        $("#CustomerId").val(row.Id);
                        $("#CustomerName").val(row.Name);
                        $('#TerminalSelectModalWindow').modal('hide');
                    }
                    catch (err) {
                        console.log(err);
                        $(this).showToastr(err);
                        return;
                    }
                }
            };

            //导出选择
            $("#export_select").click(function () {
                Export(1);
            });
            //导出全部
            $("#export_all").click(function () {
                Export(2);
            });
            var Export = function (t) {
                var queryParams = {};
                queryParams.type = t;
                queryParams.selectData = "";
                if (t == 1) {
                    var selectData = "";
                    //获取用户选择的单据
                    var arrselections = $("input[name='btSelectItem']:checked").each(function (i, j) {//把所有被选中的复选框的值存入数组
                        selectData += (selectData != "" ? "," : "") + $(this).val();
                    });

                    if (selectData == "") {
                        $(this).showToastr("没有选择数据");
                        return false;
                    }
                    queryParams.selectData = selectData;

                }
                BindQueryParams(queryParams);
                window.location.href = "/RecordingVoucher/Export?type=" + queryParams.type + "&selectData=" + queryParams.selectData + "&recordName=" + queryParams.RecordName + "&generateModeId=" + queryParams.GenerateModeId + "&billNumber=" + queryParams.BillNumber + "&summary=" + queryParams.Summary + "&accountingOptionId=" + queryParams.AccountingOptionId + "&accountingOptionName=" + queryParams.AccountingOptionName + "&auditedStatus=" + queryParams.AuditedStatus + "&startTime=" + queryParams.StartTime + "&endTime=" + queryParams.EndTime + "&billTypeId=" + queryParams.BillTypeId;

            }

            //绑定查询参数
            var BindQueryParams = function (queryParams) {
                queryParams.RecordName = $("#RecordName").val();
                queryParams.GenerateModeId = $("#GenerateModeId").val();
                queryParams.BillNumber = $("#BillNumber").val();
                queryParams.Summary = $("#Summary").val();
                queryParams.AccountingOptionId = $("#AccountingOptionId").val();
                queryParams.AccountingOptionName = $("#AccountingOptionName").val();
                queryParams.AuditedStatus = $("#AuditedStatus").val();
                queryParams.StartTime = $("#StartTime").val();
                queryParams.EndTime = $("#EndTime").val();
                queryParams.BillTypeId = $("#BillTypeId").val();
            }

            //防止重复查询
            var queryNumber = 1;
            $("#btn_query").click(function () {
                if (queryNumber > 1) {
                    return false;
                }
                queryNumber = queryNumber + 1;
            });


        });
    </script>
}